
/************************************************************************/
//  PROJECT:............Tradegy, property rights, and the commons                 				  
//  NAME:...............Elisabeth T. Isaksen and Andries Richter                      
//  DATE:...............September 30, 2018                          			
//  Task of program: .. Masterfile		
/************************************************************************/

clear all
set matsize 3000
set maxvar 10000
set emptycells drop 
set more off, permanently 
prog drop _all
mac drop _all


// Dropbox location
global DB C:\Users\elisa\Dropbox (Privat)\
global home ${DB}TragedyPropertyCommons_ETI\


// Location of programs and ado-files
sysdir set PLUS "${home}STATA\ado\plus"
sysdir set PERSONAL "${home}STATA\ado\personal"
sysdir list


// Additional Stata packages needed to run the code:
/*
ssc install estout , replace
ssc install distinct , replace
ssc install ftools , replace
ssc install ivreg2 , replace
ssc install xtivreg2 , replace
ssc install listtex , replace
ssc install parmest , replace
ssc install reghdfe , replace   
ssc install spmap , replace
ssc install ranktest  , replace
ssc install weakiv  , replace
ssc install avar  , replace
*/



*******************************************
********  Macros: paths  ******************
*******************************************

global fileformat pdf 
global resolution 


/*
global fileformat png 
global resolution width(1000) 
*/


global data ${home}STATA\Data_in\
global dataOut ${home}STATA\Data_out\
global ArcGIS ${home}ArcGIS\Excel\
global QGIS ${home}QGIS\Excel\
global EEZBoundaries   ${data}

global dofiles ${home}STATA\Dofiles\JAERE\

global tables ${home}\LaTeX\TablesJAERE\
global figures ${home}\LaTeX\FiguresJAERE\

global tablesAPP ${home}\LaTeX\TablesJAERE_Appendix\
global figuresAPP ${home}\LaTeX\FiguresJAERE_Appendix\



*******************************************
********  Macros: analysis  ***************
*******************************************

global Treatment ppr_implemented_cc    			 
global TreatmentGroup ppr_cc_2006             
global NonTreatmentGroup non_ppr_cc_2006       	

global yearlist 1975 2005 
global Varlist_Fishery undeveloped developing fully_exploited OverXRec collapsed Recovering explstatus_num3 IntoCollapse  $TreatmentGroup  $Treatment
global Varlist_Specie  lrealprice_taxon  K highly_migratory
global Varlist_EEZ lSST MeanCollapse_2
global Varlist_Country lgdp_capita_c pop_growth trade law_average polity2  lIEAnumagreecum
global Varlist_MAIN Varlist_Fishery Varlist_Specie Varlist_EEZ Varlist_Country

global ControlsNone   
global ControlsShort  L(0/0).MeanCollapse_2     L(0/0).lgdp_capita_c  L(0/0).pop_growth 
global ControlsMedium L(0/5).MeanCollapse_2     L(0/0).lgdp_capita_c  L(0/0).pop_growth 			  
global ControlsLong   L(0/5).MeanCollapse_2     L(0/0).lgdp_capita_c  L(0/0).pop_growth  ///
					  L(0/0).lrealprice_taxon   L(0/0).polity2     	  L(0/0).lIEAnumagreecum    ///
					  L(0/2).lSST				L(0/0).trade  	  

global Instrument_5    L5.ppr_other_num_time
global Instrument_N_5  L5.ppr_other_num_time_neighbour

global TimeMin 30
global TimeMax 40

global ClusterLevel CountryID

global PriceYearStart 1961
global PriceYearEnd   2005


***********************
**** Run programs   ***
***********************

// My ttests
do "${dofiles}1_myttests.do"


*********************************************
**** Open dataset   *************************
*********************************************

cd "${data}"
use  "${dataOut}EEZ_expl_trimmed_adjusted_20180921" , clear

******************************************************
****   Section 3: Data and Descriptives  *************
****   Section 4: Empirical strategy     *************
******************************************************

do "${dofiles}2_PPR_Descriptives_20180918.do"
	*Figure 1: The roll out of PPRs over time. 1950-2005
			*PPR_Implemented_ver2
			*PPR_impl_annual
	*Table 2: Summary statistics for 1975 and 2005, by PPR and non-PPR fisheries
			*sum_Varlist_Fishery_1975_2005
			*sum_Varlist_Specie_1975_2005
			*sum_Varlist_EEZ_1975_2005
			*sum_Varlist_Country_1975_2005
	* Figure 2: Collapsed stocks, by PPR and non-PPR fisheries. 1950-2006
			*collapsed_ppr_cc
			*IntoCollapse_ppr_cc_BAR
	* Figure 3: Roll-out of PPRs over time in fisheres and other env domanins
			*PPR_Impl_Own_Other2


******************************************************
****   Section 5.1: DiD results    *******************
******************************************************

do "${dofiles}2_PPR_Empirical_DiD_Event_20180914.do"
	*Figure 4: The effect of PPRs on probability of collapse
			*Event_Collapse_2y_NoControls
			*Event_Collapse_2y_ControlsLong
			*Event_IntoCollapse_2y_NoControls
			*Event_IntoCollapse_2y_ControlsLong
			
do "${dofiles}2_PPR_Empirical_DiD_20180927.do"
	*Table 3: The effect of PPRs on probability of collapse
			*DID_collapsed_20170322_plain.tex
			*DID_IntoCollapse_20170322_plain.tex
			*DID_info_20170322.tex
			
			

******************************************************
****   Section 5.2: IV-DiD results    ****************
******************************************************

do "${dofiles}2_PPR_Empirical_IV_20180921.do"	
	*Table 4: First stage	
			*FS_IV_plain_20170921
			*FS_IV_info_20170921
	*Table 5: Second stage	
			*IV_collapsed_plain_20170921.tex
			*IV_IntoCollapse_plain_20170921.tex
			*IV_info_20170322.tex
			*IV_info_20170921.tex
			*IV_info_AR_collapsed.tex
			*IV_info_AR_IntoCollapsed
			*IV_info_ARCSET_collapsed      --> Takes a long time to run
			*IV_info_ARCSET_IntoCollapsed  --> Takes a long time to run


******************************************************
****   Section 5.3: Heterogenous effects   ***********
******************************************************

do "${dofiles}2_PPR_Empirical_DiD_Event_R3_Trans_NonTrans_20180927.do"
	*Figure 5: The effect of PPRs on collapse (transferable vs. non-transferable)
			*FS_IV_plain_20170921
			*FS_IV_info_20170921
	*Table 6: The effect of PPRs on probability of collapse. Transferable vs. non-transferable	
			*DID_collapsed_plain_TRANS_NONTRANS_20170921
			*DID_IntoCollapse_plain_TRANS_NONTRANS_20170921
			*DID_info_TRANS_nonTRANS_20170921
	


do "${dofiles}2_PPR_Empirical_Heterogenous_Event_20180914.do"
	*Figure 6: Heterogenous effects (country and species characteristics)
			*Hist_RoL_TC
			*Hist_K_TC
			*Hist_Trade_TC
			*Hist_Price_TC --> Numbers slightly different than what is in the submitted paper
			*Event_Collapse_2y_ControlsLong_RoL_Low
			*Event_Collapse_2y_ControlsLong_RoL_High
			*Event_Collapse_2y_ControlsLong_Trade_Low
			*Event_Collapse_2y_ControlsLong_Trade_High
			*Event_Collapse_2y_ControlsLong_K_Low
			*Event_Collapse_2y_ControlsLong_K_High
			*Event_Collapse_2y_ControlsLong_Price_High
			*Event_Collapse_2y_ControlsLong_Price_Low



******************************************************
****   Section 6.1: Predictions   ********************
******************************************************

do "${dofiles}2_PPR_Predictions_GetCoeffPoly_20180914.do"
	*Datasets:
		*${dataOut}Poly_PPR_K
		*${dataOut}Poly_PPR_Price
		*${dataOut}Poly_PPR_GDP
		*${dataOut}Poly_PPR_Trade
		*${dataOut}Poly_High_Low_ROL
do "${dofiles}2_PPR_Predictions_Calculate_20180914.do"
	*Datasets
		*${dataOut}PPR_K_id_eez_tax
		*${dataOut}PPR_Price_id_eez_tax
		*${QGIS}Map_Predictions_20180917.csv
		*${dataOut}PPR_Predictions
do "${dofiles}2_PPR_Predictions_Combine_20180914.do"		
	*Figure 7
		//STATA maps  (Deactivated)
		*Map_PPR_Mean_K_Price 
		*Map_PPR_Mean_Trade_GDP_ROLH
		*Map_PPR_Mean_K_Price_Trade_GDP_ROLH
		
		//QGIS maps	
		*QGIS_Map_PPR_Mean_K_Price_crop
		*QGIS_Map_PPR_Mean_Trade_GDP_ROLH_crop
		*QGIS_Map_PPR_Mean_K_Price_Trade_GDP_ROLH_crop	
